<?php    
    class WZ_DbObject 
    {
        public function __call($method, $args)
        {
            $methodCalled = substr($method, 0, 3);
            if ($methodCalled == 'get') {
                $uncamelizeMethod = \WZ_Inflector::uncamelize(lcfirst(substr($method, 3)));
                $var = strtolower($uncamelizeMethod);
                if (isset($this->$var)) {
                    return $this->$var;
                }
                return null;
            } elseif ($methodCalled == 'set') {
                $uncamelizeMethod = \WZ_Inflector::uncamelize(lcfirst(substr($method, 3)));
                $var = strtolower($uncamelizeMethod);
                $this->$var = $args[0];
            }
        }
        
        public function save()
        {
            $db = \WZ_Singleton::WZ_Activerecord($this->WZDbTable);
            $primary = $db->getPrimary();
            $vars = get_object_vars($this);
            unset($vars['WZDbTable']);
            $update = false;
            $data = array();
            foreach ($vars as $key => $value) {
                if ($key == $primary) {
                    $update = true;
                    $identity = $value;
                } else {
                    $data[$key] = $value;
                }
            }

            if (true === $update) {
                return $db->update($data, "$primary = '$identity'");
            } else {
                return $db->insert($data);
            }
        }
    }